package com.woniu.finance.service.impl;

import com.woniu.finance.entity.Department;
import com.woniu.finance.entity.Menu;
import com.woniu.finance.entity.Permission;
import com.woniu.finance.mapper.MenuMapper;
import com.woniu.finance.mapper.PermissionMapper;
import com.woniu.finance.service.IPermissionService;
import com.woniu.util.utils.HttpResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 权限表 服务实现类
 * </p>
 *
 * @author 刘品水
 * @since 2023-04-25
 */
@Service
public class PermissionServiceImpl implements IPermissionService {
    @Autowired(required = false)
    private PermissionMapper permissionMapper;
    @Override
    public HttpResult<?> findAllPermission() {
        try {
            List<Permission> permissions = permissionMapper.selectList(null);
            return new HttpResult<>().ok(permissions);
        } catch (Exception e) {
            e.printStackTrace();
            return new HttpResult<>().fail();
        }
    }

    @Override
    public HttpResult<?> savePermission(Permission permission) {
        try {
            permissionMapper.insert(permission);
            return new HttpResult<>().ok();
        } catch (Exception e) {
            e.printStackTrace();
            return new HttpResult<>().fail();
        }
    }

    @Override
    public HttpResult<?> modifyPermission(Permission permission) {
        try {
            permissionMapper.updateById(permission);
            return new HttpResult<>().ok();
        } catch (Exception e) {
            e.printStackTrace();
            return new HttpResult<>().fail();
        }
    }

    @Override
    public HttpResult<?> removePermissionById(Integer id) {
        try {
            int delete = permissionMapper.deleteById(id);
            return new HttpResult<>().ok();
        } catch (Exception e) {
            e.printStackTrace();
            return new HttpResult<>().fail();
        }
    }

    @Override
    public HttpResult<?> findPermissionById(Integer id) {
        try {
            Permission permission = permissionMapper.selectById(id);
            return new HttpResult<>().ok(permission);
        } catch (Exception e) {
            e.printStackTrace();
            return new HttpResult<>().fail();
        }
    }
}
